package com.mymoney.beans;

import java.sql.Timestamp;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import com.google.appengine.api.datastore.Key;


@Entity
public class ItemBean {

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Key id;
	
	@Basic
	private String name = null;
	
	@OneToMany(cascade = CascadeType.ALL)
	private StoreBean store = null;
	
	@ManyToOne(cascade = CascadeType.ALL)
	private CategoryBean category = null;
	
	@Basic
	private double price;
	
	@Basic
	private Timestamp planDate = null;
	
	@Basic
	private Timestamp buyDate = null;
	
	@OneToOne(cascade = CascadeType.ALL)
	private CurrencyBean currency = null;
	
	@Basic
	private int isBought;
	
	@Basic
	private long code;
	
	@Basic
	private String primaryAccount = null;
	
	public Key getId() {
		return id;
	}


	public void setId(Key id) {
		this.id = id;
	}

	
	public StoreBean getStore() {
		return store;
	}


	public void setStore(StoreBean store) {
		this.store = store;
	}


	public CategoryBean getCategory() {
		return category;
	}


	public void setCategory(CategoryBean category) {
		this.category = category;
	}


	public double getPrice() {
		return price;
	}


	public void setPrice(double price) {
		this.price = price;
	}


	public CurrencyBean getCurrency() {
		return currency;
	}


	public void setCurrency(CurrencyBean currency) {
		this.currency = currency;
	}
	
	
	public int isBought() {
		return isBought;
	}


	public void setBought(int isBought) {
		this.isBought = isBought;
	}
	
	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}

	public Timestamp getPlanDate() {
		return planDate;
	}


	public void setPlanDate(Timestamp planDate) {
		this.planDate = planDate;
	}


	public Timestamp getBuyDate() {
		return buyDate;
	}


	public void setBuyDate(Timestamp buyDate) {
		this.buyDate = buyDate;
	}

	@Override
	public boolean equals(Object obj) {

		if (obj == null) {
			return false;
		}

		if(this == obj) {
			return true;
		}

		if (!(obj instanceof ItemBean)) {
			return false;
		}

		ItemBean other = (ItemBean) obj;
		if ((id == null) || (other.getId() == null)) {
			return false;
		}

		return (id.equals(other.getId()));
	}


	public long getCode() {
		return code;
	}


	public void setCode(long code) {
		this.code = code;
	}


	public String getPrimaryAccount() {
		return primaryAccount;
	}


	public void setPrimaryAccount(String primaryAccount) {
		this.primaryAccount = primaryAccount;
	}
}
